package com.woniuxy.mq.controller;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yellow Doctor
 * @date 2025-03-26
 * @desc 蜗牛创想：www.woniuxy.com
 */
@RestController
@RequestMapping("msg2")
public class MessageController3 {
    /**
     * 消息发送模板
     */
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMsgTopic")
    public ResponseEntity<String> sendMsgDirect() {
        //发送消息 是 3个参数
        //参数1  exchange 的名称
        //参数2  exchange 和 队列绑定的 routingkey
        //参数3  消息
        rabbitTemplate.convertAndSend("topic.exchange", "gz.tianhe.news","广州天河"); // 2个队列都会去
        rabbitTemplate.convertAndSend("topic.exchange","tianhe.news","广州天河柯木塱"); // 只能去 queue2
        rabbitTemplate.convertAndSend("topic.exchange","sz.news","深圳福田世界之窗"); //   只能去 queue2
        rabbitTemplate.convertAndSend("topic.exchange","gz.th.kelumang.news","蜗牛学院毕业..."); // 只能去 queue2
        rabbitTemplate.convertAndSend("topic.exchange","gz.yuexiu.news","越秀公园"); //2个队列都会去
        rabbitTemplate.convertAndSend("topic.exchange","abc","广州天河蜗牛学院");  //哪里都去了不

        return ResponseEntity.ok("消息发送成功");
    }

    @GetMapping("/send/confirm/{msg}")
    public String sendMsg(@PathVariable("msg") String msg){

            /**
             * 参数1：交换机
             * 参数2：路由
             * 参数3：msg
             */
            rabbitTemplate.convertAndSend(
                    "confirm.direct.exchange",
                    "msg.confirm",
                    msg);
            return "发送成功...";
    }

    @GetMapping("/send/dlx/{msg}")
    public String sendDLXMsg(@PathVariable("msg") String msg){

        /**
         * 参数1：交换机
         * 参数2：路由
         * 参数3：msg
         */
        rabbitTemplate.convertAndSend(
                "normal.exchange",
                "city.gz",
                msg);
        return "发送成功...";
    }
}
